package edu.lsnu.equipment_management_system.service.impl;

import edu.lsnu.equipment_management_system.exception.*;
import edu.lsnu.equipment_management_system.mapper.select.nopaging.PowerCheckMapper;
import edu.lsnu.equipment_management_system.pojo.po.entity.*;
import edu.lsnu.equipment_management_system.pojo.vo.in.*;
import edu.lsnu.equipment_management_system.pojo.vo.out.session.UserVo;
import edu.lsnu.equipment_management_system.pojo.vo.sql_conditions.PasswordAndUserNoVo;
import edu.lsnu.equipment_management_system.service.*;
import edu.lsnu.equipment_management_system.util.MD5Util;
import edu.lsnu.equipment_management_system.util.MyStringUtil;
import lombok.Data;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.PropertySource;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import javax.servlet.http.HttpSession;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;

/**
 * @author mzy
 * @Description
 * @date 2018/11/26
 */
@Service
@Data
@PropertySource({"classpath:resource.properties"})
@ConfigurationProperties(prefix = "equipment.no")
@Transactional(propagation= Propagation.REQUIRED)
public class TransactionalCollectionServiceImpl implements TransactionalCollectionService {
    private int length;


    @Autowired
    UpdateEquipmentUseRecordTableEndDateService updateEquipmentUseRecordTableEndDateService;
    @Autowired
    TableOperationService tableOperationService;
    @Autowired
    CheckUserAndEquipmentDoesNotExistService checkUserAndEquipmentDoesNotExistService;
    @Autowired
    PowerCheckMapper powerCheckMapper;

    private void powerCheck(String equipmentNo, String userNo) throws NoPowerException {
        List<String> allEquipmentNo = powerCheckMapper.getALLUsingEquipmentNo(userNo);

        if (!allEquipmentNo.contains(equipmentNo)) {
            throw new NoPowerException();
        }
    }

    /**
     * @Description 管理员增加用户的逻辑代码
     * @author mzy
     * @time 2018-11-26
     * @see
     * @return   boolean
     * @params  []
     */
    @Override
    public boolean adminAddUser(UserTablePo userTablePo) throws NoExistException, UserNoException, NotNumericException {
        // 数据库中多了触发器之后，insert不返回count了，顾抛弃res的insertcount校验，哎！
        boolean res = false;

        if (null != userTablePo.getUserNo() &&
                null != userTablePo.getUserName() &&
                null != userTablePo.getPassword() &&
                null != userTablePo.getTeacherOfficeNo()) {
            String userNo = userTablePo.getUserNo().trim();

            // 确保职工号是8位
            if (userNo.length() != 8) {
                throw new UserNoException();
            }
            // 如果用户编号不全为数字
            if (!MyStringUtil.isNumericByJavaDefault(userNo)) {
                throw new NotNumericException();
            }
            boolean bool = checkUserAndEquipmentDoesNotExistService.checkUserNoDoesNotExist(userTablePo.getUserNo());
            if (bool) {
                // md5加密
                String password = MD5Util.md5(userTablePo.getPassword());

                userTablePo.setPassword(password);

                tableOperationService.insertIntoUserTable(userTablePo);
                // res = tableOperationService.insertIntoUserTable(userTablePo);

                res = true;
            } else {
                throw new NoExistException();
            }


        }
        return res;
    }

    /**
     * @Description 设备用户之间转让的事务聚簇集合
     *      先在上一条使用记录加上结束时间；
     *      再插入一条新的useRecord。
     * @author mzy
     * @time 2018-11-26
     * @see
     * @return   boolean
     * @params  [equipmentUseRecordTablePo, session]
     */
    @Override
    public boolean equipmentChangeUser(EquipmentUseRecordTablePo equipmentUseRecordTablePo, HttpSession session) throws NoPowerException, NoNotExistException, InsertIntoEquipmentUseRecordTableException {
        // 数据库中多了触发器之后，insert不返回count了，顾抛弃res的insertcount校验，哎！
        // 默认res最开始时false
        boolean res = false;
        // System.err.println(equipmentUseRecordTablePo);
        // 判断equipmentUseRecordTablePo中不应该为空的是否为空，为空直接false
        if (equipmentUseRecordTablePo.getEquipmentNo() != null &&
                equipmentUseRecordTablePo.getBeginDate() != null &&
                equipmentUseRecordTablePo.getPlaceNo() != null &&
                equipmentUseRecordTablePo.getUserNo() != null) {
            // 不为空的情况下：先拿到需要转让设备的equipmentNo
            String equipmentNo = equipmentUseRecordTablePo.getEquipmentNo();
            // 把UserVo拿出来
            UserVo user = (UserVo) session.getAttribute("user");
            // 确保userVo不为空，为空又直接false
            if (null != user) {
                String previousUserNo = /*"50830030";*/ user.getUserNo();

                boolean bool = checkUserAndEquipmentDoesNotExistService.checkEquipmentNoDoesNotExist(equipmentNo);
                if (bool) {
                    throw new NoNotExistException();
                }

                powerCheck(equipmentNo, previousUserNo);

                // 常理上应该先为上条使用记录先加上结束时间，再插入一条新的使用记录
                // 但是因为我有判断如果插入记录为（同一天同一个人同一个设备，则不能多次插入），会中断
                // 此时应该先判断能否insert，先后顺序要明确；这里也是事务处理不当造成的，应该把事务包到当前的聚簇操作层
                tableOperationService.insertIntoEquipmentUseRecordTable(equipmentUseRecordTablePo);

                updateEquipmentUseRecordTableEndDateService.updateEndTimeToPreviousEquipmentUseRecord(equipmentNo, previousUserNo);

                /*
                res = updateEquipmentUseRecordTableEndDateService.updateEndTimeToPreviousEquipmentUseRecord(equipmentNo, previousUserNo);
                if (res) {
                    res = tableOperationService.insertIntoEquipmentUseRecordTable(equipmentUseRecordTablePo);
                }
                */
                res = true;
            }
        }
        return res;
    }

    /**
     * @Description 设备购入添加使用人的事务聚簇集合
     *      先增加一个设备基本信息的记录JBXX_SB
     *      然后再在JBXX_SBSY中新增记录
     *      注意新增可以多条，所以要循环加入
     * @author mzy
     * @time 2018-11-26
     * @see
     * @return   boolean
     * @params  [equipmentPurchaseFromPageConvert, session]
     */
    @Override
    public boolean userEquipmentPurchase(EquipmentPurchaseFromPage equipmentPurchaseFromPage, HttpSession session) throws NoExistException, EquipmentNoSizeNotEqualNumberException, InputEquipmentNoRepeatException, NotNumericException, EquipmentNoEexception, InsertIntoEquipmentUseRecordTableException {
        // 最开始是false
        boolean res = false;

        // System.out.println(equipmentPurchaseFromPageConvert);
        // 判断equipment   中不应该为空的是否为空，为空直接false
        if (equipmentPurchaseFromPage.getEquipmentCategoryNo() != null &&
                equipmentPurchaseFromPage.getEquipmentName() != null &&
                equipmentPurchaseFromPage.getEquipmentNo() != null &&
                equipmentPurchaseFromPage.getNumber() != null &&
                equipmentPurchaseFromPage.getPlaceNo() != null &&
                equipmentPurchaseFromPage.getPrice() != null &&
                equipmentPurchaseFromPage.getPurchaseDate() != null &&
                equipmentPurchaseFromPage.getUtilizationTemplateNo() != null) {
            UserVo user = (UserVo) session.getAttribute("user");
            if (null != user) {
                // split，解决：从普通的FromPage到Convert
                EquipmentPurchaseFromPageConvert equipmentPurchaseFromPageConvert = new EquipmentPurchaseFromPageConvert();

                List<String> equipmentNoList = splitStringToList(equipmentPurchaseFromPage.getEquipmentNo());
                BeanUtils.copyProperties(equipmentPurchaseFromPage, equipmentPurchaseFromPageConvert);
                equipmentPurchaseFromPageConvert.setEquipmentNo(equipmentNoList);
                // -_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_^_^

                HashSet tmpSet = new HashSet();
                for (String equipmentNo : equipmentNoList) {
                    // --------输入编号重复检查---------
                    tmpSet.add(equipmentNo);

                    // ---------检查设备编号是不是数字-------
                    if (!MyStringUtil.isNumericByJavaDefault(equipmentNo)) {
                        throw new NotNumericException();
                    }
                    //---------设备编号最多十位数字---------
                    if (equipmentNo.length() > length) {
                        throw new EquipmentNoEexception();
                    }
                }
                if (tmpSet.size() < equipmentNoList.size()) {
                    throw new InputEquipmentNoRepeatException();
                }
                // -_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_^_^

                String userNo = user.getUserNo();
                // String userNo = "001";
                List<EquipmentInformationTablePo> informationTablePoList = new ArrayList<>();
                List<EquipmentUseRecordTablePo> useRecordTablePoList = new ArrayList<>();

                int size = equipmentPurchaseFromPageConvert.getEquipmentNo().size();

                // 如果数量不等于requipmentNo的size则抛出异常
                if (size != equipmentPurchaseFromPageConvert.getNumber()) {
                    throw new EquipmentNoSizeNotEqualNumberException();
                }
                // -_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_^_^

                for (int i=0; i<size; i++) {
                    EquipmentInformationTablePo equipmentInformationTablePo = new EquipmentInformationTablePo();
                    EquipmentUseRecordTablePo equipmentUseRecordTablePo = new EquipmentUseRecordTablePo();

                    BeanUtils.copyProperties(equipmentPurchaseFromPageConvert, equipmentInformationTablePo);
                    BeanUtils.copyProperties(equipmentPurchaseFromPageConvert, equipmentUseRecordTablePo);

                    String equipmentNo = equipmentPurchaseFromPageConvert.getEquipmentNo().get(i);

                    if (! checkUserAndEquipmentDoesNotExistService.checkEquipmentNoDoesNotExist(equipmentNo)) {
                        throw new NoExistException();
                    }
                    equipmentInformationTablePo.setEquipmentSource("购入");
                    equipmentInformationTablePo.setEquipmentNo(equipmentNo);
                    equipmentInformationTablePo.setNumber(1);

                    equipmentUseRecordTablePo.setBeginDate(equipmentPurchaseFromPageConvert.getPurchaseDate());
                    equipmentUseRecordTablePo.setUserNo(userNo);
                    equipmentUseRecordTablePo.setEquipmentNo(equipmentNo);

                    informationTablePoList.add(equipmentInformationTablePo);
                    useRecordTablePoList.add(equipmentUseRecordTablePo);

                    // System.out.println(equipmentInformationTablePo);
                    // System.out.println(equipmentUseRecordTablePo);
                }
                /*
                for (int i=0; i<size; i++) {
                    res = tableOperationService.insertIntoEquipmentInformationTable(informationTablePoList.get(i));
                }
                if (res) {
                    for (int i=0; i<size; i++) {
                        tableOperationService.insertIntoEquipmentUseRecordTable(useRecordTablePoList.get(i));
                    }
                }
                */
                for (int i=0; i<size; i++) {
                    tableOperationService.insertIntoEquipmentInformationTable(informationTablePoList.get(i));
                }
                for (int i=0; i<size; i++) {
                    tableOperationService.insertIntoEquipmentUseRecordTable(useRecordTablePoList.get(i));
                }
                res = true;
            }

        }

        return res;
    }


    /**
     * @Description 调入设备的事务聚簇集合
     *      先要填写调入的JBXX_DRDC表
     *      再填写JBXX_SB
     *      再填写JBXX_SBSY
     *      注意是可以多个的，所以注意for循环。
     * @author mzy
     * @time 2018-11-27
     * @see
     * @return   boolean
     * @params  [equipmentTransferInFromPageConvert, session]
     */
    @Override
    public boolean userEquipmentTransferIn(EquipmentTransferInFromPage equipmentTransferInFromPage, HttpSession session) throws NoExistException, EquipmentNoSizeNotEqualNumberException, InputEquipmentNoRepeatException, NotNumericException, EquipmentNoEexception, InsertIntoEquipmentUseRecordTableException {
        // 最开始是false
        boolean res = false;
        if (equipmentTransferInFromPage.getTranserInUnit() != null ||
                "".equals(equipmentTransferInFromPage.getTranserInUnit())) {
            equipmentTransferInFromPage.setTranserInUnit("计算机科学学院");
        }

        // System.out.println(equipmentPurchaseFromPage);
        // 判断equipment   中不应该为空的是否为空，为空直接false
        if (equipmentTransferInFromPage.getEquipmentCategoryNo() != null &&
                equipmentTransferInFromPage.getEquipmentName() != null &&
                equipmentTransferInFromPage.getEquipmentNo() != null &&
                equipmentTransferInFromPage.getNumber() != null &&
                equipmentTransferInFromPage.getPlaceNo() != null &&
                equipmentTransferInFromPage.getPrice() != null &&
                equipmentTransferInFromPage.getPurchaseDate() != null &&
                equipmentTransferInFromPage.getTranserDate() != null &&
                equipmentTransferInFromPage.getTranserOutUnit() != null &&
                equipmentTransferInFromPage.getUtilizationTemplateNo() != null) {
            UserVo user = (UserVo) session.getAttribute("user");
            if (null != user) {
                // split，解决：从普通的FromPage到Convert
                EquipmentTransferInFromPageConvert equipmentTransferInFromPageConvert = new EquipmentTransferInFromPageConvert();

                List<String> equipmentNoList = splitStringToList(equipmentTransferInFromPage.getEquipmentNo());
                BeanUtils.copyProperties(equipmentTransferInFromPage, equipmentTransferInFromPageConvert);
                equipmentTransferInFromPageConvert.setEquipmentNo(equipmentNoList);
                // -_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_^_^

                HashSet tmpSet = new HashSet();
                for (String equipmentNo : equipmentNoList) {
                    // --------输入编号重复检查---------
                    tmpSet.add(equipmentNo);

                    // ----------确保编号全部是数字-----------
                    if (!MyStringUtil.isNumericByJavaDefault(equipmentNo)) {
                        throw new NotNumericException();
                    }

                    //---------设备编号最多十位数字---------
                    if (equipmentNo.length() > length) {
                        throw new EquipmentNoEexception();
                    }
                }
                if (tmpSet.size() < equipmentNoList.size()) {
                    throw new InputEquipmentNoRepeatException();
                }
                // -_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_^_^

                String userNo = user.getUserNo();
                // String userNo = "001";
                List<EquipmentTransferTablePo> transferTablePoList = new ArrayList<>();
                List<EquipmentInformationTablePo> informationTablePoList = new ArrayList<>();
                List<EquipmentUseRecordTablePo> useRecordTablePoList = new ArrayList<>();

                int size = equipmentTransferInFromPageConvert.getEquipmentNo().size();

                // 如果数量不等于requipmentNo的size则抛出异常
                if (size != equipmentTransferInFromPageConvert.getNumber()) {
                    throw new EquipmentNoSizeNotEqualNumberException();
                }
                // -_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_^_^

                for (int i=0; i<size; i++) {
                    EquipmentTransferTablePo equipmentTransferTablePo = new EquipmentTransferTablePo();
                    EquipmentInformationTablePo equipmentInformationTablePo = new EquipmentInformationTablePo();
                    EquipmentUseRecordTablePo equipmentUseRecordTablePo = new EquipmentUseRecordTablePo();

                    BeanUtils.copyProperties(equipmentTransferInFromPageConvert, equipmentTransferTablePo);
                    BeanUtils.copyProperties(equipmentTransferInFromPageConvert, equipmentInformationTablePo);
                    BeanUtils.copyProperties(equipmentTransferInFromPageConvert, equipmentUseRecordTablePo);


                    String equipmentNo = equipmentTransferInFromPageConvert.getEquipmentNo().get(i);

                    if (! checkUserAndEquipmentDoesNotExistService.checkEquipmentNoDoesNotExist(equipmentNo)) {
                        throw new NoExistException();
                    }
                    equipmentTransferTablePo.setUserNo(userNo);
                    equipmentTransferTablePo.setTranserOr("调入");
                    equipmentTransferTablePo.setEquipmentNo(equipmentNo);

                    equipmentInformationTablePo.setEquipmentSource("调入");
                    equipmentInformationTablePo.setEquipmentNo(equipmentNo);
                    equipmentInformationTablePo.setNumber(1);

                    equipmentUseRecordTablePo.setBeginDate(equipmentTransferInFromPageConvert.getTranserDate());
                    equipmentUseRecordTablePo.setUserNo(userNo);
                    equipmentUseRecordTablePo.setEquipmentNo(equipmentNo);

                    transferTablePoList.add(equipmentTransferTablePo);
                    informationTablePoList.add(equipmentInformationTablePo);
                    useRecordTablePoList.add(equipmentUseRecordTablePo);

                    // System.out.println(equipmentInformationTablePo);
                    // System.out.println(equipmentUseRecordTablePo);
                }

                for (int i=0; i<size; i++) {
                    // 先JBXX_SB
                    tableOperationService.insertIntoEquipmentInformationTable(informationTablePoList.get(i));

                }
                for (int i=0; i<size; i++) {
                    // 再JBXX_DRDC
                    tableOperationService.insertIntoEquipmentTransferTable(transferTablePoList.get(i));
                }
                for (int i=0; i<size; i++) {
                    // 再JBXX_SBSY
                    tableOperationService.insertIntoEquipmentUseRecordTable(useRecordTablePoList.get(i));
                }

                res = true;
                /*
                if (res) {
                    for (int i=0; i<size; i++) {
                        // 再JBXX_DRDC
                        res = tableOperationService.insertIntoEquipmentTransferTable(transferTablePoList.get(i));
                    }
                    if (res) {
                        for (int i=0; i<size; i++) {
                            // 再JBXX_SBSY
                            tableOperationService.insertIntoEquipmentUseRecordTable(useRecordTablePoList.get(i));
                        }
                    }
                }
                */
            }

        }

        return res;
    }

    /**
     * @Description 设备调出的事务聚簇集合
     *      先填写调入调出表
     *      然后把运行使用中当前设备SYRQ2为空的记录给补齐
     * @author mzy
     * @time 2018-11-27
     * @see
     * @return   boolean
     * @params  [equipmentTransferOutFromPage, session]
     */
    @Override
    public boolean userEquipmentTransferOut(EquipmentTransferOutFromPage equipmentTransferOutFromPage, HttpSession session) throws NoNotExistException, NoPowerException {
        // 默认res最开始时false
        boolean res = false;
        if (equipmentTransferOutFromPage.getTranserOutUnit() != null ||
                "".equals(equipmentTransferOutFromPage.getTranserOutUnit())) {
            equipmentTransferOutFromPage.setTranserOutUnit("计算机科学学院");
        }


        // 判断equipmentDamageFromPage有没有不能为空的值为空的情况！
        if (equipmentTransferOutFromPage.getEquipmentNo() != null &&
                equipmentTransferOutFromPage.getTranserDate() != null &&
                equipmentTransferOutFromPage.getTranserInUnit() != null) {

            EquipmentTransferTablePo equipmentTransferTablePo = new EquipmentTransferTablePo();
            // 把fromPage copy到tablePo中
            BeanUtils.copyProperties(equipmentTransferOutFromPage, equipmentTransferTablePo);
            // System.out.println(equipmentTransferOutFromPage);
            // System.out.println(equipmentTransferTablePo);

            String equipmentNo = equipmentTransferTablePo.getEquipmentNo();
            boolean bool = checkUserAndEquipmentDoesNotExistService.checkEquipmentNoDoesNotExist(equipmentNo);
            if (bool) {
                throw new NoNotExistException();
            }

            // 获取到userNo往里面塞
            UserVo user = (UserVo) session.getAttribute("user");
            if (null != user) {
                String userNo = /*"001";*/ user.getUserNo();
                powerCheck(equipmentNo, userNo);

                equipmentTransferTablePo.setUserNo(userNo);
                equipmentTransferTablePo.setTranserOr("调出");
                /*
                res = tableOperationService.insertIntoEquipmentTransferTable(equipmentTransferTablePo);
                if (res) {
                    res = updateEquipmentUseRecordTableEndDateService.updateEndTimeToPreviousEquipmentUseRecord(equipmentNo, userNo);
                }
                */
                tableOperationService.insertIntoEquipmentTransferTable(equipmentTransferTablePo);
                updateEquipmentUseRecordTableEndDateService.updateEndTimeToPreviousEquipmentUseRecord(equipmentNo, userNo);

                res = true;
            }
        }

        return res;
    }

    /**
     * @Description 用户报损报废设备的事务聚簇集合代码
     *      先在报损报废中插入一条记录
     *      再把当前设备在运行使用中的SYRQ2为空的记录给加上结束时间
     * @author mzy
     * @time 2018-11-26
     * @see
     * @return   boolean
     * @params  [equipmentDamageFromPage, session]
     */
    @Override
    public boolean userEquipmentDamage(EquipmentDamageFromPage equipmentDamageFromPage, HttpSession session) throws NoNotExistException, NoPowerException {
        // 默认res最开始时false
        boolean res = false;
        // 判断equipmentDamageFromPage有没有不能为空的值为空的情况！
        if (equipmentDamageFromPage.getDamageDate() != null &&
                equipmentDamageFromPage.getDamageOr() != null &&
                equipmentDamageFromPage.getDepreciationPeriod() != null &&
                equipmentDamageFromPage.getUseYear() != null &&
                equipmentDamageFromPage.getEquipmentNo() != null) {

            EquipmentDamageTablePo equipmentDamageTablePo = new EquipmentDamageTablePo();
            // 把fromPage copy到tablePo中
            BeanUtils.copyProperties(equipmentDamageFromPage, equipmentDamageTablePo);
            // System.out.println(equipmentDamageFromPage);
            // System.out.println(equipmentDamageTablePo);
            String equipmentNo = equipmentDamageTablePo.getEquipmentNo();
            boolean bool = checkUserAndEquipmentDoesNotExistService.checkEquipmentNoDoesNotExist(equipmentNo);
            if (bool) {
                throw new NoNotExistException();
            }

            // 获取到userNo往里面塞
            UserVo user = (UserVo) session.getAttribute("user");
            if (null != user) {
                String userNo = /*"001";*/ user.getUserNo();
                powerCheck(equipmentNo, userNo);

                equipmentDamageTablePo.setUserNo(userNo);

                /*
                res = tableOperationService.insertIntoEquipmentDamageTable(equipmentDamageTablePo);
                if (res) {
                    res = updateEquipmentUseRecordTableEndDateService.updateEndTimeToPreviousEquipmentUseRecord(equipmentNo, userNo);
                }
                */
                tableOperationService.insertIntoEquipmentDamageTable(equipmentDamageTablePo);
                updateEquipmentUseRecordTableEndDateService.updateEndTimeToPreviousEquipmentUseRecord(equipmentNo, userNo);

                res = true;
            }
        }

        return res;
    }

    /**
     * @Description 设备维修维护的逻辑代码
     * @author mzy
     * @time 2018-11-27
     * @see
     * @return   boolean
     * @params  [equipmentRepairFromPage, session]
     */
    @Override
    public boolean userEquipmentRepair(EquipmentRepairFromPage equipmentRepairFromPage, HttpSession session) throws NoNotExistException, NoPowerException, InsertIntoEquipmentRepairTableException {
        boolean res = false;
        if (equipmentRepairFromPage.getEquipmentNo() != null &&
                equipmentRepairFromPage.getRepairOr() !=  null &&
                equipmentRepairFromPage.getRepairDate() != null &&
                equipmentRepairFromPage.getRepairMoney() != null
                ) {
            EquipmentRepairTablePo equipmentRepairTablePo = new EquipmentRepairTablePo();
            // 把fromPage copy到tablePo中
            BeanUtils.copyProperties(equipmentRepairFromPage, equipmentRepairTablePo);
            // System.out.println(equipmentRepairFromPage);
            // System.out.println(equipmentRepairTablePo);
            String equipmentNo = equipmentRepairTablePo.getEquipmentNo();
            boolean bool = checkUserAndEquipmentDoesNotExistService.checkEquipmentNoDoesNotExist(equipmentNo);
            if (bool) {
                throw new NoNotExistException();
            }

            // 获取到userNo往里面塞
            UserVo user = (UserVo) session.getAttribute("user");
            if (null != user) {
                String userNo = /*"001";*/ user.getUserNo();
                powerCheck(equipmentNo, userNo);

                equipmentRepairTablePo.setUserNo(userNo);
                if (null == equipmentRepairTablePo.getRepairOr() || "".equals(equipmentRepairTablePo.getRepairOr())) {
                    equipmentRepairTablePo.setRepairOr("维修");
                }

                equipmentRepairTablePo.setRemark(equipmentRepairTablePo.getRepairReason());

                // res = tableOperationService.insertIntoEquipmentRepairTable(equipmentRepairTablePo);
                tableOperationService.insertIntoEquipmentRepairTable(equipmentRepairTablePo);

                res = true;
            }
        }
        return res;
    }

    /**
     * @Description 处理
     * @author mzy
     * @time 2018-12-01
     * @see
     * @return   java.util.List<java.lang.String>
     * @params  [equipmentNo]
     */
    private List<String> splitStringToList(String equipmentNo) {
        List<String> array = new ArrayList<>();

        String tmp = equipmentNo.replaceAll("，", ",");
        // System.out.println(tmp);
        String[] split = tmp.split(",");

        for (int i=0; i<split.length; i++) {
            split[i] = split[i].trim();
        }

        for(String str : split) {
            if (!"".equals(str)) {
                array.add(str);
            }
        }

        return array;
    }
}